#include "../include/EchoParser.h"

using namespace std;
int main(int argc, char* argv[])
{
	for(int i = 1; i < argc; i++)
	{
		EchoParser p;
		
		//Loads XML file into memory
		p.readXmlFile(argv[i]);
		
		//Actually parses it
		p.process();
		
		//Extract generic track info
		
		/*
		When extracting singular values from the XML document, use getScalarAttr(nameAsInXML) to get the value returned to you
		directly
		*/
		
		cout << "Total Track Duration: " << p.getScalarAttr("duration") << endl;
		cout << "Loud Max Mean: " << p.getScalarAttr("loudnessMaxMean") << endl;
		cout << "No. of segments: " << p.getScalarAttr("numSegments") << endl;
		cout << "No. of sections: " << (p.getSectionStarts())->size() << endl;
		
		vector<float> starts = (* (p.getSectionStarts() ) );
		vector<float> durations = (* (p.getSectionDurations() ) );
		for(unsigned int i = 0; i < (p.getSectionStarts())->size(); i++)
		{
			//
			
			cout << "Section " << (i+1) << " start: " << starts[i] << ", duration: " << durations[i] << endl;
		}
		
		/*
		Note: p.getNumTatums() and p.getScalarAttr("numTatums") do
		the same exact thing.
		*/
		
		cout << "No. of tatums: " << p.getNumTatums() << endl;
		cout << "1st Tatum: " << p.getTatum(0) << endl;
		cout << "2nd Tatum: " << p.getTatum(1) << endl;
		cout << "5th Tatum: " << p.getTatum(4) << endl;
		cout << "Last Tatum: " << p.getTatum(p.getNumTatums() - 1) << endl;
		
		/*
		This is how you deal with the non-singular vector values
		*/
		float* timbreMeans = p.getVectorAttr("timbreMean");
		for(int i = 0; i < 12; i++)
		{
			cout << "Timbre Mean #" << i + 1 << ": " << timbreMeans[i] << endl;
		}
		
		//Get vector/array of Segment pointers
		vector<Segment*>* segments = p.getSegments();
		cout << "There are " << segments->size() << " Segments in the vector" << endl;
		
		//Get BeatObjects
		std::vector<BeatObject*>* bos = p.getBeatObjects(1);
		printf("Found %d BeatObjects\n", bos->size());
		
		for(unsigned int x = 0; x < bos->size(); x++)
		{
			BeatObject* obj = (*bos)[x];
			printf("\tTatum: %f, Char: %c\n", obj->m_tatum, obj->m_char);
		}
		
		
		//Access 3 random segments
		
		Segment* s1 = (*segments)[0];
		Segment* s2 = (*segments)[6];
		Segment* s3 = (*segments)[11];
		
		//Print out their info
		/*
		Note: See Segment.h for the methods that you can call
		to retrieve specific info from the Segments
		*/
		
		/*
		Here's how to extract tatum-specific data from a segment
		*/
		cout << "Avg. Tatums per Segment: " << p.getAverageTatumsPerSegment() << endl;
		cout << "Number of Tatums in Seg ID#" << s2->getId() << ": " << s2->getNumTatums() << ". The value of the first tatum is " << s2->getTatum(0) << " and the value of the last one is " << s2->getTatum(s2->getNumTatums() - 1) << endl;
		
		s1->print();
		s2->print();
		s3->print();
		
		
		//Will print out each Segment that the Parser maintains
		//p.print();
	}
}

